package com.gxy.learn.design.model.behaviour.responsibility;

import lombok.extern.slf4j.Slf4j;

/**
 * @description: 抽象处理类
 * @author: gaoxueyong
 * @Date: 2022/11/8 15:37
 */
@Slf4j
public abstract class Handler {
    protected final static int NUM_ONE = 1;
    protected final static int NUM_THREE = 3;
    protected final static int NUM_SEVEN = 7;
    //该领导处理的清求天数区间
    private int numStart;
    private int numEnd;
    //声明后续者(声明上级领导)
    private Handler nextHandler;

    public Handler(int numStart) {
        this.numStart = numStart;
    }

    public Handler(int numStart, int numEnd) {
        this.numStart = numStart;
        this.numEnd = numEnd;
    }
    /**
     * 设置上级领导对象
     * @Author gaoxueyong
     * @Date 3:47 下午 2022/11/8
     * @Param [nextHandler]
     * @return void
     **/
    public void setNextHandler(Handler nextHandler){
        this.nextHandler = nextHandler;
    }
    /**
     * 各级领导处理请假条
     * @Author gaoxueyong
     * @Date 3:47 下午 2022/11/8
     * @Param [leaveRequest]
     * @return void
     **/
    protected abstract void handlerLeave(LeaveRequest leaveRequest);

    /**
     * 审批
     * @Author gaoxueyong
     * @Date 3:47 下午 2022/11/8
     * @Param [leaveRequest]
     * @return void
     **/
    public final void audit(LeaveRequest leaveRequest){
        if(leaveRequest.getNum()<=0){
            log.info("请假天数不能小于0！流程结束！");
            return;
        }
        if(leaveRequest.getNum() <=this.numEnd){
    //        领导进行审批
            this.handlerLeave(leaveRequest);
        }else if(leaveRequest.getNum() > this.numEnd && this.nextHandler!=null ){
            //            提交给上级领导进行审批
            this.nextHandler.audit(leaveRequest);
        }else if(leaveRequest.getNum()>Handler.NUM_SEVEN){
            log.info("超过最大请假天数，不允许提交！流程结束！");
        }else{
            log.info("流程结束！");
        }
    }
}